package com.rd.student.dashuju.wangbo.day08_07;

import java.io.*;
import java.util.ArrayList;
import java.util.Random;

public class DLT {

    public static void main(String[] args) throws Exception {
        File file1 = new File("daletou.txt");
        File file2 = new File("randomDLT.txt");
        File file3 = new File("num.txt");
        file1.delete();
        file2.delete();
        int num = 0;
        ArrayList arrayList1 = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        arrayList1 = dltWin();
        for (int i = 0; i < 100; i++) {
            arrayList2 = buy();
            if (arrayList1.equals(arrayList2)){
                num++;
                System.out.println("您中奖了！");
            }
        }
        OutputStream os = new FileOutputStream(file3);
        os.write(num);
        os.close();
    }

    public static ArrayList dltWin() throws Exception{
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        ArrayList list = new ArrayList();
        for (int i = 0; i < 5; i++) {
            int ran =random.nextInt(35)+1;
            if (!list.contains(ran)){
                list.add(ran);
                sb.append(ran + " ");
            }else i--;
        }
        sb.append("| ");
        for (int i = 0; i < 2; i++) {
            int ran =random.nextInt(12)+1;
            if (!list.contains(ran)){
                list.add(ran);
                sb.append(ran + " ");
            }else i--;
        }
        PrintStream ps = new PrintStream(
                new FileOutputStream("daletou.txt",true),true);
        System.setOut(ps);
        System.out.println(sb);
        ps.close();
        return list;
    }

    public static ArrayList buy() throws FileNotFoundException {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        ArrayList list = new ArrayList();
        for (int i = 0; i < 5; i++) {
            int ran =random.nextInt(35)+1;
            if (!list.contains(ran)){
                list.add(ran);
                sb.append(ran + " ");
            }else i--;
        }
        sb.append("| ");
        for (int i = 0; i < 2; i++) {
            int ran =random.nextInt(12)+1;
            if (!list.contains(ran)){
                list.add(ran);
                sb.append(ran + " ");
            }else i--;
        }
        PrintStream ps = new PrintStream(
                new FileOutputStream("randomDLT.txt",true),true);
        System.setOut(ps);
        System.out.println(sb);
        ps.close();

        return list;
    }
}

